package com.jy.api.dao;

import com.jy.api.domain.*;
import com.jy.api.signUpReq.stock.RecordDetailsSignUpReq;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by lihu on 2018/2/1.
 */
public interface StockTransactionDao extends JpaRepository<StockChangeTransaction, String> {

    /**
     * 获取单次盘点所有记录
     *
     * @param refId
     * @return
     */
    List<StockChangeTransaction> findByRefIdOrderByIdDesc(String refId);


    /***
     * 条件查询商品出入库信息
     *
     * @param signUpReq
     * @return
     */
    List<Map<String, Object>> queryStockDetails(RecordDetailsSignUpReq signUpReq);


    /***
     * 条件查询商品出入库总数量
     *
     * @param signUpReq
     * @return
     */
    long queryStockDetailsNumber(RecordDetailsSignUpReq signUpReq);

    List<StockChangeTransaction> findListByRefIdAndStoreId(String refId, String storeId);

    Page<StockChangeTransaction> findListBySkuIdAndTypeAndStockLevel(String skuId, StockType type, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findByStoreIdAndAddTimeBetweenAndTypeAndSource(String storeId, Date begin, Date end, StockType type, StockChangeReason reason, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndStockLevelOrderByAddTimeDesc(String storeId, Date time, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndTypeAndAddTimeGreaterThanEqualAndStockLevelOrderByAddTimeDesc(String storeId, StockType type, Date time, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndOperatorIdAndStockLevelOrderByAddTimeDesc(String storeId, Date time, String operatorId, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndSkuIdAndStockLevelOrderByAddTimeDesc(String storeId, Date time, String skuId, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndTypeAndSkuIdAndAddTimeGreaterThanEqualAndStockLevelOrderByAddTimeDesc(String storeId, StockType type, String skuId, Date time, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndTypeAndOperatorIdAndAddTimeGreaterThanEqualAndStockLevelOrderByAddTimeDesc(String storeId, StockType type, String opId, Date time, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndTypeAndOperatorIdAndSkuIdAndAddTimeGreaterThanEqualAndStockLevelOrderByAddTimeDesc(String storeId, StockType type, String opId, String skuId, Date time, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndSkuIdAndOperatorIdAndStockLevelOrderByAddTimeDesc(String storeId, Date time, String skuId, String opId,  StockLevel level,Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndTypeAndStockLevelOrderByAddTimeDesc(String storeId, Date time, StockType type, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndSourceAndStockLevelOrderByAddTimeDesc(String storeId, Date time, StockChangeReason source, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndSourceAndTypeAndStockLevelOrderByAddTimeDesc(String storeId, Date time, StockChangeReason source, StockType type, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndSourceAndSkuIdAndStockLevelOrderByAddTimeDesc(String storeId, Date time, StockChangeReason source, String skuId, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndTypeAndSkuIdAndStockLevelOrderByAddTimeDesc(String storeId, Date time, StockType type, String skuId, StockLevel level, Pageable pageable);

    Page<StockChangeTransaction> findAllByStoreIdAndAddTimeGreaterThanEqualAndTypeAndSkuIdAndSourceAndStockLevelOrderByAddTimeDesc(String storeId, Date time, StockType type, String skuId, StockChangeReason source, StockLevel level, Pageable pageable);





}
